package com.fang.transfer.file.client.listener;

import com.fang.transfer.file.client.AppContext;
import com.fang.transfer.file.client.thread.SendUDPAddrService;
import com.fang.transfer.file.client.transfer.UdpService;
import com.fang.transfer.file.common.RequestListener;
import com.fang.transfer.file.common.code.ServiceSendCode;
import com.fang.transfer.file.common.model.TransferFileRequest;

/**
 * 开启UPD,并通知服务器UDP地址
 */
public class UDPInfoSynListener extends RequestListener<TransferFileRequest> {

    @Override
    public void handle(TransferFileRequest param) throws Exception {
        AppContext.transferFileRequestMap.put(param.getId(), param);
        System.out.println("开启线程发送udp请求");
        UdpService udpService = new UdpService(param);
        AppContext.udpServiceMap.put(param.getId(), udpService);
        AppContext.poolExecutor.execute(new SendUDPAddrService(param));
    }

    @Override
    public String getCode() {
        return ServiceSendCode.RUN_UDP_ADDR_SYN;
    }
}
